﻿using Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    /// <summary>
    /// 字典表
    /// </summary>
    public class DictionaryDal : BaseDal<SysDictionary>
    {
        public override string tablename
        {
            get { return "SysDictionary"; }
        }

        public override Dictionary<string, bool> PKName
        {
            get {
                Dictionary<string, bool> dic = new Dictionary<string, bool>();
                dic.Add("dictionary_Id", true);
                return dic;
            }
        }

        /// <summary>
        /// 绑定下拉框
        /// </summary>
        /// <returns></returns>
        public List<SysDictionary> sb(int i)
        {
            List<dynamic> type1 = EnumHelperDic.EnumListDic<EnumSelectType>();
            for (int b = 0; b < type1.Count; b++)
            {
                if (type1[b].value == i)
                {
                    return DictionaryList(i);
                }
            
            }
            return null;    
            
        }
        public List<SysDictionary> DictionaryList(int type)
        {
            SqlParameter[]
                Parameter = new SqlParameter[]{
                    new SqlParameter("@dictionary_Type",type)
                };
            string Sql = Common.Common.GetTable<SysDictionary>(tablename, Parameter);
            DataTable dt = Common.DBHelp.GetDataSet(Sql);


            List<SysDictionary> Dictionary = new List<SysDictionary>();
            foreach (DataRow item in dt.Rows)
            {
                SysDictionary Dictionary1 = new SysDictionary();
                foreach (var i in Dictionary1.GetType().GetProperties())
                {
                    i.SetValue(Dictionary1, item[i.Name]);
                }
                Dictionary.Add(Dictionary1);
            }
            return Dictionary;

        }
    }
}
